package com.yy.controller.user;

import com.yy.controller.service.AddressBookService;
import com.yy.entity.AddressBook;
import com.yy.result.Result;
import com.yy.vo.AddressBookVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/addressBook")
@Slf4j
@Api(tags = "地址相关接口")
public class AddressBookController {
    @Autowired
    private AddressBookService addressBookService;

    @GetMapping("/list")
    @CrossOrigin
    @ApiOperation("获取地址列表")
    public Result<List<AddressBookVo>> list() {
        List<AddressBookVo> addressBookVoList = addressBookService.list();
        return Result.success(addressBookVoList);
    }

    @PostMapping("/add")
    @CrossOrigin
    @ApiOperation("添加地址")
    public Result add(@RequestBody AddressBook addressBook) {
        addressBookService.add(addressBook);
        return Result.success();
    }

    @PostMapping("/edit")
    @CrossOrigin
    @ApiOperation("修改地址")
    public Result edit(@RequestBody AddressBook addressBook) {
        addressBookService.upadte(addressBook);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    @CrossOrigin
    @ApiOperation("根据id删除地址")
    public Result delete(@PathVariable Long id) {
        addressBookService.delete(id);
        return Result.success();
    }
}
